<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use Kafka;
class ConsumerKafka extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'command:kafka';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '处理异步kafka消息';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return int
     */
    public function handle()
    {
        $config=Kafka\ConsumerConfig::getInstance();
        $config->setMetadataRefreshIntervalMs(500);
        $config->setMetadataBrokerList('localhost:9092');
        //组
        $config->setGroupId('text1');
        $config->setBrokerVersion('1.0.0');
        $config->setTopics(['test']);
        $conssumer =new Kafka\Consumer();
        $conssumer->start(function ($topic,$part,$message){
            var_dump($topic);
            var_dump($part);
            var_dump($message);
        });
        return 0;
    }

}
